var t = require("../../@babel/runtime/helpers/interopRequireDefault"), e = require("../../@babel/runtime/helpers/defineProperty"), a = require("../../@babel/runtime/helpers/toConsumableArray"), i = t(require("./dateParserTime")), s = getApp();

Page({
    data: {
        unreadCount: 0,
        messageType: [],
        msgTypeUrl: {
            img1: "/packageE/stationNotice/stationNoticeLogistics/stationNoticeLogistics",
            img2: "/packageE/stationNotice/stationNoticeExtract/stationNoticeExtract",
            img3: "/packageE/stationNotice/stationNoticeExamine/stationNoticeExamine",
            img4: "/packageE/stationNotice/stationNoticeCustomer/stationNoticeCustomer",
            img5: "/packageE/stationNotice/stationNoticeProperty/stationNoticeProperty",
            img6: "/packageE/stationNotice/stationNoticeAnchor/stationNoticeAnchor",
            img7: "/packageE/stationNotice/stationNoticeOrder/stationNoticeOrder",
            img8: "/packageE/stationNotice/stationNoticeActivity/stationNoticeActivity",
            img9: "/packageE/stationNotice/stationNoticekefu/stationNoticekefu",
            img10: "/packageI/stationNotice/stationStore/stationStore"
        },
        weekMessage: [],
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        msg_body_types: {
            1: {
                title: "商品名",
                desc: "快递单号",
                img: "商品图"
            },
            2: {
                applyTime: "申请时间",
                amounts: "提现金额",
                pay_way_name: "提现方式"
            },
            3: {
                title: "直播间标题",
                desc: "提示语",
                img: "直播间封面图"
            },
            4: {
                title: "",
                nickname: "会员昵称",
                pay_time: "付款时间",
                order_sn: "订单编号",
                goodsName: "商品名",
                pay_money: "订单金额"
            },
            5: {
                changeTime: "时间",
                changeType: "类型",
                changeNum: "变动金额",
                afterChange: "变动后",
                order_sn: "订单编号（结算通知才有）",
                order_amount: "订单金额（结算通知才有）",
                mall_amount: "商城销售额（结算通知才有）",
                amount: "分红结算金额（结算通知才有）",
                dividend_amount: "分红奖励金额（结算通知才有）"
            },
            6: {
                title: "直播间标题",
                img: "直播间封面图"
            },
            7: {
                nickname: "昵称",
                time: "时间",
                order_sn: "订单编号",
                goodsName: "商品名",
                pay_money: "订单金额",
                refund_money: "退款金额"
            },
            10: {
                apply_time: "申请时间",
                nickname: "会员:",
                store_name: "门店名称:",
                apply_id: "申请记录ID:"
            }
        }
    },
    onLoad: function(t) {
        console.log(i.default), this.getIndexData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    setMessageRead: function() {
        var t = this, e = s.getNetAddresss("plugin.instation-message.api.message.read-message");
        s._postNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return t.tips(a.msg);
                t.data.page = 1, t.data.isLoadMore = !0, t.data.total_page = 0, t.getIndexData();
            }
        });
    },
    onShareAppMessage: function() {},
    getIndexData: function() {
        var t = this, e = s.getNetAddresss("plugin.instation-message.api.message.index");
        s._postNetWork({
            url: e,
            data: {
                basic_info: 1
            },
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return t.tips(a.msg);
                var s = a.data.messageType, o = a.data.weekMessage.data, n = 0;
                s.forEach(function(t) {
                    t.last_time = (0, i.default)(t.last_time), n += t.no_read;
                }), o.forEach(function(t) {
                    t.created_at = (0, i.default)(t.created_at);
                }), t.data.isLoadMore = !0, t.data.total_page = a.data.weekMessage.last_page, t.data.total_page || (t.data.total_page = 0), 
                t.setData({
                    messageType: s,
                    unreadCount: n,
                    weekMessage: o
                });
            }
        });
    },
    _getMoreData: function() {
        var t = this, e = this;
        if (!(this.data.page >= this.data.total_page)) {
            var o = s.getNetAddresss("plugin.instation-message.api.message.index");
            this.data.page++, s._postNetWork({
                url: o,
                data: {
                    page: this.data.page
                },
                success: function(s) {
                    var o = s.data;
                    if (1 == o.result) {
                        o.data.weekMessage.current_page >= o.data.weekMessage.last_page && e.setData({
                            isLoadMore: !1
                        });
                        var n = o.data.weekMessage.data;
                        n.forEach(function(t) {
                            t.created_at = (0, i.default)(t.created_at);
                        });
                        var r = t.data.weekMessage;
                        r.push.apply(r, a(n)), t.setData({
                            weekMessage: r
                        });
                    }
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    gotoPages: function(t) {
        var a = this, i = t.currentTarget.dataset.item, o = t.currentTarget.dataset.index, n = s.getNetAddresss("plugin.instation-message.api.message.read-message");
        s._postNetWork({
            url: n,
            data: {
                id: i._id
            },
            success: function(t) {
                var i = t.data;
                if (1 != i.result) return a.tips(i.msg);
                var s = "weekMessage[" + o + "].is_read";
                a.setData(e({}, s, 0));
            }
        });
        var r = i.mini_url;
        if ("" != r && null != r) if (10 != i.type_id) wx.navigateTo({
            url: r
        }); else {
            var g = i.msg_body.apply_id;
            wx.navigateTo({
                url: r + "?id=" + g
            });
        }
    },
    gotoSetting: function() {
        wx.navigateTo({
            url: "/packageE/stationNotice/stationNoticeSetting/stationNoticeSetting"
        });
    },
    gotoMessagePage: function(t) {
        var a, i = t.currentTarget.dataset.index, s = this.data.unreadCount - this.data.messageType[i].no_read, o = "messageType[" + i + "].no_read";
        this.setData((e(a = {}, o, 0), e(a, "unreadCount", s), a));
        var n = t.currentTarget.dataset.url;
        wx.navigateTo({
            url: this.data.msgTypeUrl[n]
        });
    },
    tips: function(t) {
        return wx.showToast({
            title: t,
            icon: "none",
            duration: 2e3
        }), !1;
    }
});